package com.netty.timeold.model;

import java.nio.charset.StandardCharsets;
import java.util.UUID;

import com.sevenchildren.framework.entity.BiStringEntry;
import com.sevenchildren.framework.util.JacksonUtils;

public class BaseModel {

	private String resp;

	public String toJson() {
		return JacksonUtils.toJson(this);
	}

	@Override
	public String toString() {
		return toJson();
	}

	public static byte[] toArray(String header, String json) {
		if (null == json || null == header) {
			return null;
		}
		return header.concat(json).getBytes(StandardCharsets.UTF_8);
	}

	public static String getHeader() {
		return UUID.randomUUID().toString();
	}

	public static BiStringEntry parse(String body) {
		if (null == body) {
			return null;
		}
		if (36 > body.length()) {
			return new BiStringEntry(body, "");
		}
		return new BiStringEntry(body.substring(0, 36), body.substring(36));
	}

	public String getResp() {
		return resp;
	}

	public void setResp(String resp) {
		this.resp = resp;
	}

}
